css: Fold color value computation into gtksymboliccolor.c
authorBenjamin Otte <otte@redhat.com>
Sat, 14 Jul 2012 18:24:46 +0000 (20:24 +0200)
committerBenjamin Otte <otte@redhat.com>
Tue, 28 Aug 2012 13:40:56 +0000 (15:40 +0200)
This gets rid of the public function
_gtk_css_rgba_value_compute_from_symbolic().
The fallback is now handled using a switch statement instead of letting
the caller pass the function.

gtk/gtkcssimagelinear.c
gtk/gtkcssrgbavalue.c
gtk/gtkcssrgbavalueprivate.h
gtk/gtkcssshadowvalue.c
gtk/gtkcssstylepropertyimpl.c
gtk/gtksymboliccolor.c

index e6440232a23b5f5bf27be1e9ae1434c599361acf..10977e8ff21a6b2e9ef8b37fb8f5792d9d25093e 100644 (file)
@@ -413,10 +413,8 @@ gtk_css_image_linear_compute (GtkCssImage     *image,
                               guint            property_id,
                               GtkStyleContext *context)
 {
-  static const GdkRGBA transparent = { 0, 0, 0, 0 };
   GtkCssImageLinear *linear = GTK_CSS_IMAGE_LINEAR (image);
   GtkCssImageLinear *copy;
-  GtkCssValue *fallback;
   guint i;
 
   copy = g_object_new (GTK_TYPE_CSS_IMAGE_LINEAR, NULL);
@@ -424,7 +422,6 @@ gtk_css_image_linear_compute (GtkCssImage     *image,
 
   copy->angle = _gtk_css_value_compute (linear->angle, property_id, context);
   
-  fallback = _gtk_css_symbolic_value_new_take_symbolic_color (gtk_symbolic_color_new_literal (&transparent));
   g_array_set_size (copy->stops, linear->stops->len);
   for (i = 0; i < linear->stops->len; i++)
     {
@@ -433,10 +430,7 @@ gtk_css_image_linear_compute (GtkCssImage     *image,
       stop = &g_array_index (linear->stops, GtkCssImageLinearColorStop, i);
       scopy = &g_array_index (copy->stops, GtkCssImageLinearColorStop, i);
               
-      scopy->color = _gtk_css_rgba_value_compute_from_symbolic (stop->color,
-                                                                fallback,
-                                                                context,
-                                                                FALSE);
+      scopy->color = _gtk_css_value_compute (stop->color, property_id, context);
       
       if (stop->offset)
         scopy->offset = _gtk_css_value_compute (stop->offset, property_id, context);
@@ -444,8 +438,6 @@ gtk_css_image_linear_compute (GtkCssImage     *image,
         scopy->offset = NULL;
     }
 
-  _gtk_css_value_unref (fallback);
-
   return GTK_CSS_IMAGE (copy);
 }
 
index fc1642c392a0cf7a50c2508fe7cb9f0c752b4234..7a641a3a7764c02837538f8e06809e4c2f83322a 100644 (file)
@@ -102,41 +102,3 @@ _gtk_css_rgba_value_get_rgba (const GtkCssValue *rgba)
 
   return &rgba->rgba;
 }
-
-GtkCssValue *
-_gtk_css_rgba_value_compute_from_symbolic (GtkCssValue     *symbolic,
-                                           GtkCssValue     *fallback,
-                                           GtkStyleContext *context,
-                                           gboolean         for_color_property)
-{
-  GtkCssValue *resolved, *current;
-
-  g_return_val_if_fail (symbolic != NULL, NULL);
-
-  /* The computed value of the ‘currentColor’ keyword is the computed
-   * value of the ‘color’ property. If the ‘currentColor’ keyword is
-   * set on the ‘color’ property itself, it is treated as ‘color: inherit’. 
-   */
-  if (for_color_property)
-    {
-      GtkStyleContext *parent = gtk_style_context_get_parent (context);
-
-      if (parent)
-        current = _gtk_style_context_peek_property (parent, GTK_CSS_PROPERTY_COLOR);
-      else
-        current = _gtk_css_style_property_get_initial_value (_gtk_css_style_property_lookup_by_id (GTK_CSS_PROPERTY_COLOR));
-    }
-  else
-    {
-      current = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR);
-    }
-  
-  resolved = _gtk_style_context_resolve_color_value (context, current, symbolic);
-
-  if (resolved == NULL)
-    return _gtk_css_rgba_value_compute_from_symbolic (fallback, NULL, context, for_color_property);
-
-  g_assert (resolved->class == &GTK_CSS_VALUE_RGBA);
-  return resolved;
-}
-
index 539473fb400fdb79060629a1cf09594808da4eb8..4a2909dde4ced26b5ace4a6db760c90685140cf1 100644 (file)
@@ -28,12 +28,6 @@ G_BEGIN_DECLS
 
 GtkCssValue *   _gtk_css_rgba_value_new_from_rgba (const GdkRGBA          *rgba);
 
-GtkCssValue *   _gtk_css_rgba_value_compute_from_symbolic
-                                                  (GtkCssValue            *symbolic,
-                                                   GtkCssValue            *fallback,
-                                                   GtkStyleContext        *context,
-                                                   gboolean                for_color_property);
-
 const GdkRGBA * _gtk_css_rgba_value_get_rgba      (const GtkCssValue      *rgba);
 
 
index dfd3b1c992b7eb1f523a7e52ed8f178793e8400d..3351d6f8dd11f7bba530529339e1449a842261df 100644 (file)
@@ -64,22 +64,12 @@ gtk_css_value_shadow_compute (GtkCssValue     *shadow,
                               guint            property_id,
                               GtkStyleContext *context)
 {
-  GdkRGBA transparent = { 0, 0, 0, 0 };
-  GtkCssValue *color, *fallback;
-
-  fallback = _gtk_css_symbolic_value_new_take_symbolic_color (gtk_symbolic_color_new_literal (&transparent));
-  color = _gtk_css_rgba_value_compute_from_symbolic (shadow->color,
-                                                     fallback,
-                                                     context,
-                                                     FALSE);
-  _gtk_css_value_unref (fallback);
-
   return gtk_css_shadow_value_new (_gtk_css_value_compute (shadow->hoffset, property_id, context),
                                    _gtk_css_value_compute (shadow->voffset, property_id, context),
                                    _gtk_css_value_compute (shadow->radius, property_id, context),
                                    _gtk_css_value_compute (shadow->spread, property_id, context),
                                    shadow->inset,
-                                   color);
+                                   _gtk_css_value_compute (shadow->color, property_id, context));
 }
 
 static gboolean
index 162ab3a69ff8075d16e683cd7a2393a64adc20f9..bf7fa993f80f2fddab8a464f0dfb8167a9365291 100644 (file)
@@ -185,10 +185,7 @@ color_compute (GtkCssStyleProperty    *property,
                GtkStyleContext        *context,
                GtkCssValue            *specified)
 {
-  return _gtk_css_rgba_value_compute_from_symbolic (specified,
-                                                    _gtk_css_style_property_get_initial_value (property),
-                                                    context,
-                                                    FALSE);
+  return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
 }
 
 static GtkCssValue *
@@ -196,14 +193,7 @@ color_property_compute (GtkCssStyleProperty    *property,
                         GtkStyleContext        *context,
                         GtkCssValue            *specified)
 {
-  GtkCssValue *value;
-
-  value = _gtk_css_rgba_value_compute_from_symbolic (specified,
-                                                    _gtk_css_style_property_get_initial_value (property),
-                                                    context,
-                                                    TRUE);
-  _gtk_css_rgba_value_get_rgba (value);
-  return value;
+  return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
 }
 
 static void
index fe8656d0bc1abb74dde8409740551e5e6296aa84..8429bbc67b6c9ec4fcfaf27c9db7b11a8becbbfe 100644 (file)
@@ -17,6 +17,8 @@
 
 #include "config.h"
 #include "gtkcssrgbavalueprivate.h"
+#include "gtkcssstylepropertyprivate.h"
+#include "gtkstylepropertyprivate.h"
 #include "gtksymboliccolorprivate.h"
 #include "gtkstyleproperties.h"
 #include "gtkintl.h"
@@ -117,16 +119,69 @@ gtk_css_value_symbolic_free (GtkCssValue *value)
   g_slice_free (GtkSymbolicColor, color);
 }
 
+static GtkCssValue *
+gtk_css_value_symbolic_get_fallback (guint            property_id,
+                                     GtkStyleContext *context)
+{
+  static const GdkRGBA transparent = { 0, 0, 0, 0 };
+
+  switch (property_id)
+    {
+      case GTK_CSS_PROPERTY_BACKGROUND_IMAGE:
+      case GTK_CSS_PROPERTY_BORDER_IMAGE_SOURCE:
+      case GTK_CSS_PROPERTY_TEXT_SHADOW:
+      case GTK_CSS_PROPERTY_ICON_SHADOW:
+      case GTK_CSS_PROPERTY_BOX_SHADOW:
+        return _gtk_css_rgba_value_new_from_rgba (&transparent);
+      case GTK_CSS_PROPERTY_COLOR:
+      case GTK_CSS_PROPERTY_BACKGROUND_COLOR:
+      case GTK_CSS_PROPERTY_BORDER_TOP_COLOR:
+      case GTK_CSS_PROPERTY_BORDER_RIGHT_COLOR:
+      case GTK_CSS_PROPERTY_BORDER_BOTTOM_COLOR:
+      case GTK_CSS_PROPERTY_BORDER_LEFT_COLOR:
+      case GTK_CSS_PROPERTY_OUTLINE_COLOR:
+        return _gtk_css_value_compute (_gtk_css_style_property_get_initial_value (_gtk_css_style_property_lookup_by_id (property_id)),
+                                       property_id,
+                                       context);
+      default:
+        if (property_id < GTK_CSS_PROPERTY_N_PROPERTIES)
+          g_warning ("No fallback color defined for property '%s'", 
+                     _gtk_style_property_get_name (GTK_STYLE_PROPERTY (_gtk_css_style_property_lookup_by_id (property_id))));
+        return _gtk_css_rgba_value_new_from_rgba (&transparent);
+    }
+}
+
 static GtkCssValue *
 gtk_css_value_symbolic_compute (GtkCssValue     *value,
                                 guint            property_id,
                                 GtkStyleContext *context)
 {
-  /* for now we expect this to never be called
-   * because all cases are handled via
-   * _gtk_css_rgba_value_compute_from_symbolic()
+  GtkCssValue *resolved, *current;
+
+  /* The computed value of the ‘currentColor’ keyword is the computed
+   * value of the ‘color’ property. If the ‘currentColor’ keyword is
+   * set on the ‘color’ property itself, it is treated as ‘color: inherit’. 
    */
-  g_return_val_if_reached (_gtk_css_value_ref (value));
+  if (property_id == GTK_CSS_PROPERTY_COLOR)
+    {
+      GtkStyleContext *parent = gtk_style_context_get_parent (context);
+
+      if (parent)
+        current = _gtk_style_context_peek_property (parent, GTK_CSS_PROPERTY_COLOR);
+      else
+        current = _gtk_css_style_property_get_initial_value (_gtk_css_style_property_lookup_by_id (GTK_CSS_PROPERTY_COLOR));
+    }
+  else
+    {
+      current = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR);
+    }
+  
+  resolved = _gtk_style_context_resolve_color_value (context, current, value);
+
+  if (resolved == NULL)
+    return gtk_css_value_symbolic_get_fallback (property_id, context);
+
+  return resolved;
 }
 
 static gboolean